#import "YYText.h"
#import "dfhgwhruebvhrheycontaminategeneralize.h"
#import "GKCover.h"
#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "dfhgwhruebvhrheymagnificenttunnel.h"
#import "dfhgwhruebvhrheyautomobileenroll.h"
#import "dfhgwhruebvhrheysemesterfuriousViewController.h"
@interface dfhgwhruebvhrheysemesterfuriousViewController ()
@end
@implementation dfhgwhruebvhrheysemesterfuriousViewController {
	UILabel *amount;
	UILabel *amountLabel;
	UIView *amountView;
	UILabel *cashCode;
	UIButton *refreshNo;
	UIButton *copyBtn;
	UILabel *agentLabel;
	UILabel *agent;
	UIView *line1;
	UILabel *senderLabel;
	UILabel *sender;
	UIView *line2;
	UILabel *receiverLabel;
	UILabel *receiver;
	UIView *line3;
	UILabel *contactLabel;
	UILabel *contact;
	UIView *line4;
	UIImageView *mlhuillier;
	UIImageView *rd;
	dfhgwhruebvhrheycontaminategeneralize *loanInfoView;
	UILabel *wrongLabel;
	UIButton *changeNameBtn;
	UIView *underLine1;
	UIView *changeNameView;
	UILabel *tipsLabel;
	UIButton *changeWayBtn;
	UIView *underLine2;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadUI];
}
- (UILabel *)generateInfoLabel:(NSString *)text {
	UILabel *lb = [[UILabel alloc] init];
	lb.font = [UIFont regular:15];
	lb.text = text;
	lb.textColor = @"#3B414B".dhgfywegwygeydwlearneddesignate;
	return lb;
}
- (void)loadUI {
	[self configBackIcon:@"dhgfywegwygeydwcurvereciprocal"];
	self.navigationItem.title = @"Withdraw money";
	self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
	amountView = [[UIView alloc] init];
	amountView.layer.cornerRadius = 20;
	amountView.backgroundColor = [UIColor whiteColor];
	[self.containerView addSubview:amountView];
	amount = [[UILabel alloc] init];
	amount.textColor = primary_color.dhgfywegwygeydwlearneddesignate;
	amount.font = [UIFont semiBold:36];
	[amountView addSubview:amount];
	amountLabel = [[UILabel alloc] init];
	amountLabel.text = @"Loan Amount";
	amountLabel.font = [UIFont regular:15];
	amountLabel.textColor = primary_color.dhgfywegwygeydwlearneddesignate;
	[amountView addSubview:amountLabel];
	loanInfoView = [[dfhgwhruebvhrheycontaminategeneralize alloc] init];
	loanInfoView.vlineToTopHeight = 113;
	loanInfoView.backgroundColor = [UIColor whiteColor];
	[self.containerView addSubview:loanInfoView];
	refreshNo = [UIButton buttonWithType:UIButtonTypeCustom];
	refreshNo.titleLabel.font = [UIFont regular:15];
	[refreshNo setTitle:@"Reference NO" forState:UIControlStateNormal];
	[refreshNo setTitleColor:primary_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
	[refreshNo addTarget:self action:@selector(refreshNoAction) forControlEvents:UIControlEventTouchUpInside];
	[loanInfoView addSubview:refreshNo];
	copyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	copyBtn.layer.cornerRadius = 16;
	copyBtn.titleLabel.font = [UIFont regular:14];
	[copyBtn setTitle:@"Copy" forState:UIControlStateNormal];
	copyBtn.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
	[loanInfoView addSubview:copyBtn];
	[copyBtn addTarget:self action:@selector(copyBtnAction) forControlEvents:UIControlEventTouchUpInside];
	cashCode = [[UILabel alloc] init];
	cashCode.font = [UIFont semiBold:24];
	cashCode.layer.cornerRadius = 10;
	cashCode.layer.masksToBounds = YES;
	cashCode.textAlignment = NSTextAlignmentCenter;
	cashCode.textColor = primary_color.dhgfywegwygeydwlearneddesignate;
	cashCode.backgroundColor = @"#FFEB54".dhgfywegwygeydwlearneddesignate;
	[loanInfoView addSubview:cashCode];
	agentLabel = [self generateInfoLabel:@"Agent Code"];
	[loanInfoView addSubview:agentLabel];
	agent = [self generateInfoLabel:@"Dylan Holloway"];
	[loanInfoView addSubview:agent];
	line1 = [[UIView alloc] init];
	line1.backgroundColor = @"#E6E6E6".dhgfywegwygeydwlearneddesignate;
	[loanInfoView addSubview:line1];
	senderLabel = [self generateInfoLabel:@"Sender"];
	[loanInfoView addSubview:senderLabel];
	sender = [self generateInfoLabel:@"Lois Murphy"];
	[loanInfoView addSubview:sender];
	line2 = [[UIView alloc] init];
	line2.backgroundColor = @"#E6E6E6".dhgfywegwygeydwlearneddesignate;
	[loanInfoView addSubview:line2];
	receiverLabel = [self generateInfoLabel:@"Receiver"];
	[loanInfoView addSubview:receiverLabel];
	receiver = [self generateInfoLabel:@"Evan Rodgers"];
	[loanInfoView addSubview:receiver];
	line3 = [[UIView alloc] init];
	line3.backgroundColor = @"#E6E6E6".dhgfywegwygeydwlearneddesignate;
	[loanInfoView addSubview:line3];
	mlhuillier = [[UIImageView alloc] init];
	mlhuillier.image = [UIImage imageNamed:@"get_money_ml"];
	[loanInfoView addSubview:mlhuillier];
	rd = [[UIImageView alloc] init];
	rd.image = [UIImage imageNamed:@"get_money_rd"];
	[loanInfoView addSubview:rd];
	changeNameView = [[UIView alloc] init];
	changeNameView.layer.cornerRadius = 20;
	changeNameView.backgroundColor = [UIColor whiteColor];
	[self.containerView addSubview:changeNameView];
	wrongLabel = [self generateInfoLabel:@"Wrong name, failed withdrawal？"];
	wrongLabel.textAlignment = NSTextAlignmentCenter;
	[changeNameView addSubview:wrongLabel];
	changeNameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	changeNameBtn.tag = 100;
	changeNameBtn.titleLabel.font = [UIFont semiBold:16];
	[changeNameBtn setTitle:@"Change Name" forState:UIControlStateNormal];
	[changeNameBtn setTitleColor:primary_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
	[changeNameBtn addTarget:self action:@selector(changeInfoAction:) forControlEvents:UIControlEventTouchUpInside];
	[changeNameView addSubview:changeNameBtn];
	underLine1 = [[UIView alloc] init];
	underLine1.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
	[changeNameView addSubview:underLine1];
	NSString *num1 = [[NSUserDefaults standardUserDefaults] stringForKey:dhgfywegwygeydwharmonynasty];
	NSString *num2 = [[NSUserDefaults standardUserDefaults] stringForKey:dhgfywegwygeydwnastydisposition];
	NSString *tips = [NSString stringWithFormat:@"1. For the security of your data, please fill in the mobile phone number that randomly generated on this page.\
 \n2. Mainstream cash withdrawal channels:M.Lhuillier, RD. Pawnshop\
 \n3. Please take your valid ID and the Reference NO. obtained from the APP to the RD.Pawnshop and M.Lhuillier store to get cash, and then operate according to the store staff\'s requirements.\
 \n4. Withdrawal Cash Customer Service No.Smart/Sun-%@;Globe-%@.\
 \n5. A penalty shall be paid on the first day of the overdue period, which is 10%% of the loan amount, and 3%% per day of the loan amount after the first day of the overdue. Please repayment on time, enjoy faster loan approval, higher loan amount, lower loan interest rate, Integrity builds a good life.", num1, num2];
	NSMutableAttributedString *mattribute = [[NSMutableAttributedString alloc] initWithString:tips];
	mattribute.yy_color = [UIColor whiteColor];
	mattribute.yy_lineSpacing = 5;
	mattribute.yy_font = [UIFont regular:14];
	tipsLabel = [[UILabel alloc] init];
	tipsLabel.numberOfLines = 0;
	tipsLabel.attributedText = mattribute;
	[self.containerView addSubview:tipsLabel];
	underLine2 = [[UIView alloc] init];
	underLine2.backgroundColor = @"#FFEB54".dhgfywegwygeydwlearneddesignate;
	[self.containerView addSubview:underLine2];
	changeWayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	changeWayBtn.tag = 101;
	changeWayBtn.titleLabel.font = [UIFont regular:17];
	[changeWayBtn setTitle:@"Change way of withdrawal —>" forState:UIControlStateNormal];
	[changeWayBtn setTitleColor:@"#FFEB54".dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
	[self.containerView addSubview:changeWayBtn];
	[changeWayBtn addTarget:self action:@selector(changeInfoAction:) forControlEvents:UIControlEventTouchUpInside];
	sender.text = self.codeModel.sender;
	agent.text = self.codeModel.agent_code;
	receiver.text = self.codeModel.user_name;
	cashCode.text = self.codeModel.control_number;
	amount.text = [NSString stringWithFormat:@"dhgfywegwygeydwconcealwarrant %@",self.codeModel.amount.dhgfywegwygeydwlocalitylearned];
	changeNameView.hidden = ![self.codeModel.is_modifiable isEqualToString:@"1"];
}
- (void)refreshNoAction {
	NSLog(@"刷新 code");
}
- (void)popServiceView {
	NSString *num1 = [[NSUserDefaults standardUserDefaults] stringForKey:dhgfywegwygeydwharmonynasty];
	NSString *num2 = [[NSUserDefaults standardUserDefaults] stringForKey:dhgfywegwygeydwnastydisposition];
	if (![num1 hasPrefix:@"0"]) {
		num1 = [@"0" stringByAppendingString:num1];
	}
	if (![num2 hasPrefix:@"0"]) {
		num2 = [@"0" stringByAppendingString:num2];
	}
	UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Please select the enquiry Tel to call" message:@"9:00 AM TO 18:00 PM" preferredStyle:UIAlertControllerStyleActionSheet];
	[alertVC addAction:[UIAlertAction actionWithTitle:num1 style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
		NSString *phoneString = [NSString stringWithFormat:@"tel:+63%@",num1];
		NSURL * urlPhone = [NSURL URLWithString:phoneString];
		if ([[UIApplication sharedApplication] canOpenURL:urlPhone]) {
			[[UIApplication sharedApplication] openURL:urlPhone options:@{} completionHandler:nil];
		}
	}]];
	[alertVC addAction:[UIAlertAction actionWithTitle:num2 style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
		NSString *phoneString = [NSString stringWithFormat:@"tel:+63%@",num2];
		NSURL * urlPhone = [NSURL URLWithString:phoneString];
		if ([[UIApplication sharedApplication] canOpenURL:urlPhone]) {
			[[UIApplication sharedApplication] openURL:urlPhone options:@{} completionHandler:nil];
		}
	}]];
	[alertVC addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
	}]];
	[self presentViewController:alertVC animated:YES completion:nil];
}
- (void)popChangeNameView {
	__weak typeof(self) weakSelf = self;
	dfhgwhruebvhrheyautomobileenroll *popView = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheyautomobileenroll" owner:nil options:nil].firstObject;
	popView.frame = CGRectMake(13, 0, dhgfywegwygeydwdispositionvisualize-13*2, 441);
	[popView bindCardInfo:self.codeModel.client_info];
	[GKCover coverFrom:[dfhgwhruebvhrheyoptionsaving keyWindow] contentView:popView style:GKCoverStyleTranslucent showStyle:GKCoverShowStyleCenter showAnimStyle:GKCoverShowAnimStyleCenter hideAnimStyle:GKCoverHideAnimStyleCenter notClick:YES];
	[popView btnClick:^(UIButton * _Nonnull sender, NSString * _Nonnull first, NSString * _Nonnull middle, NSString * _Nonnull last) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[GKCover hideCover];
		if (sender.tag == 200) {
			[strongSelf changeCashLoanNameRequest:first withMiddle:middle andLast:last];
		}
	}];
}
- (void)copyBtnAction {
	NSCharacterSet *charSet = [NSCharacterSet whitespaceCharacterSet];
	NSString *codeString = self.codeModel.control_number;
	codeString = [[codeString componentsSeparatedByCharactersInSet:charSet] componentsJoinedByString:@""];
	UIPasteboard *paste = [UIPasteboard generalPasteboard];
	paste.string = codeString;
	NSLog(@"=== %@", codeString);
	[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Copy Success!"];
}
- (void)changeCashLoanNameRequest:(NSString *)first withMiddle:(NSString *)middle andLast:(NSString *)last {
	NSMutableDictionary *params = [NSMutableDictionary dictionary];
	params[@"first_name"] = first;
	params[@"middle_name"] = middle;
	params[@"last_name"] = last;
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:changeOffLineNameApi isEncrypt:YES withParams:params success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		dfhgwhruebvhrheysternideology *model = [dfhgwhruebvhrheysternideology yy_modelWithJSON:json];
		if (model.code == 200) {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"success"];
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
	}];
}
- (void)changeInfoAction:(UIButton *)sender {
	switch (sender.tag) {
		case 100: {
			[self popChangeNameView];
		}
			break;
		case 101: {
			[self popServiceView];
		}
			break;
		default:
			break;
	}
}
- (void)backAction {
	[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)viewDidLayoutSubviews {
	[super viewDidLayoutSubviews];
	[amount mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(amountView).offset(20);
		make.centerX.equalTo(amountView);
		make.height.mas_equalTo(45);
	}];
	[amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(amount.mas_bottom).offset(10);
		make.centerX.equalTo(amount);
		make.height.mas_equalTo(21);
	}];
	[amountView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(self.containerView).offset(10);
		make.left.equalTo(self.containerView).offset(13);
		make.centerX.equalTo(self.containerView);
		make.height.mas_equalTo(115);
	}];
	[refreshNo mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(loanInfoView).offset(16);
		make.left.equalTo(loanInfoView).offset(20);
		make.height.mas_equalTo(23);
	}];
	[copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.mas_equalTo(CGSizeMake(62, 32));
		make.right.equalTo(loanInfoView).offset(-20);
		make.centerY.equalTo(refreshNo);
	}];
	[cashCode mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(copyBtn.mas_bottom).offset(8);
		make.left.equalTo(loanInfoView).offset(20);
		make.centerX.equalTo(loanInfoView);
		make.height.mas_equalTo(42);
	}];
	[agentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(cashCode.mas_bottom).offset(49);
		make.left.equalTo(loanInfoView).offset(15);
		make.height.mas_equalTo(21);
	}];
	[agent mas_makeConstraints:^(MASConstraintMaker *make) {
		make.right.equalTo(loanInfoView).offset(-15);
		make.centerY.equalTo(agentLabel);
	}];
	[line1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(agentLabel.mas_bottom).offset(10);
		make.left.right.equalTo(loanInfoView);
		make.height.mas_equalTo(0.5);
	}];
	[senderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(line1.mas_bottom).offset(20);
		make.left.equalTo(agentLabel);
		make.height.mas_equalTo(21);
	}];
	[sender mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(senderLabel);
		make.right.equalTo(agent);
	}];
	[line2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(senderLabel.mas_bottom).offset(10);
		make.left.right.equalTo(loanInfoView);
		make.height.mas_equalTo(0.5);
	}];
	[receiverLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(line2.mas_bottom).offset(20);
		make.left.equalTo(senderLabel);
		make.height.mas_equalTo(21);
	}];
	[receiver mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(receiverLabel);
		make.right.equalTo(sender);
	}];
	[line3 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(receiverLabel.mas_bottom).offset(10);
		make.left.right.equalTo(loanInfoView);
		make.height.mas_equalTo(0.5);
	}];
	[mlhuillier mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.mas_equalTo(CGSizeMake(140, 60));
		make.top.equalTo(line3.mas_bottom).offset(25);
		make.left.equalTo(loanInfoView).offset((dhgfywegwygeydwdispositionvisualize-26-280-25)/2);
	}];
	[rd mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(mlhuillier.mas_right).offset(25);
		make.size.mas_equalTo(CGSizeMake(140, 60));
		make.centerY.equalTo(mlhuillier);
	}];
	[loanInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(amountView.mas_bottom).offset(15);
		make.bottom.equalTo(rd.mas_bottom).offset(30);
		make.left.centerX.equalTo(amountView);
	}];
	[loanInfoView drawArcAndLine:nil];
	if([self.codeModel.is_modifiable isEqualToString:@"1"]) {
		[changeNameView mas_makeConstraints:^(MASConstraintMaker *make) {
			make.top.equalTo(loanInfoView.mas_bottom).offset(15);
			make.height.mas_equalTo(80).priorityHigh();
			make.left.centerX.equalTo(loanInfoView);
		}];
		[wrongLabel mas_makeConstraints:^(MASConstraintMaker *make) {
			make.top.equalTo(changeNameView).offset(12);
			make.centerX.equalTo(changeNameView);
			make.height.mas_equalTo(25);
		}];
		[changeNameBtn mas_makeConstraints:^(MASConstraintMaker *make) {
			make.top.equalTo(wrongLabel.mas_bottom).offset(5);
			make.centerX.equalTo(wrongLabel);
			make.height.mas_equalTo(25);
		}];
		[underLine1 mas_makeConstraints:^(MASConstraintMaker *make) {
			make.left.bottom.centerX.equalTo(changeNameBtn);
			make.height.mas_equalTo(1);
		}];
	}
	CGFloat top = changeNameView.isHidden ? 15 : 110;
	[tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(loanInfoView.mas_bottom).offset(top);
		make.left.centerX.equalTo(loanInfoView);
		make.height.mas_equalTo(360);
	}];
	[underLine2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.bottom.equalTo(changeWayBtn);
		make.left.equalTo(changeWayBtn);
		make.right.equalTo(changeWayBtn).offset(-30);
		make.height.mas_equalTo(1);
	}];
	[changeWayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(tipsLabel.mas_bottom).offset(30);
		make.centerX.equalTo(tipsLabel);
		make.height.mas_equalTo(23);
		make.bottom.equalTo(self.containerView).offset(-40);
	}];
}
@end
